package 源码解析;

public class ThreadLocal_ {
    private static ThreadLocal<String> sThreadLocal = new ThreadLocal<>();
    private static ThreadLocal<String> sThreadLocal2 = new ThreadLocal<>();

    public static void main(String[] args) {

        sThreadLocal.set("这是在主线程中");
        System.out.println("线程名字：" + Thread.currentThread().getName() + "---" + sThreadLocal.get());
        //线程a
        new Thread(new Runnable() {
            @Override
            public void run() {
                sThreadLocal.set("这是在线程a中");
                System.out.println("线程名字：" + Thread.currentThread().getName() + "---" + sThreadLocal.get());
                sThreadLocal2.set("这是在线程a中2");
                System.out.println("线程名字：" + Thread.currentThread().getName() + "---" + sThreadLocal2.get());
            }
        }, "线程a").start();
        //线程b
        new Thread(new Runnable() {
            @Override
            public void run() {
                sThreadLocal.set("这是在线程b中");
                System.out.println("线程名字：" + Thread.currentThread().getName() + "---" + sThreadLocal.get());
            }
        }, "线程b").start();
        //线程c
        new Thread(() -> {
            sThreadLocal.set("这是在线程c中");
            System.out.println("线程名字：" + Thread.currentThread().getName() + "---" + sThreadLocal.get());
        }, "线程c").start();
    }


}
